//index.js
import api from '../../tool/requestModel.js'
const app = getApp()
Page({
	data: {
		good: {},
		dizhi: 'https://t.doule.shop/',
		id: '',
        height:"500rpx",
		backStyle:'back'
	},
    onShareAppMessage(shareInfo){
        const { from } = shareInfo;
        return {
            imageUrl: '', 
            title: '(免费)'+this.data.good.product.name,
            path: 'pages/ljcs/ljcs?share_user_id='+tt.getStorageSync("userId")+'&id='+this.data.id,
        }
    },
	onLoad: function(option) {
        console.log(option)
        let height = tt.getSystemInfoSync().screenHeight
        this.setData({
            height:height+'px'
        })
		if(option.statu){
			this.setData({
				show:true
			})
            this.setData({
				backStyle:"home"
			})
			this.getList()
		}
		
		api.ljcsChaxun({
				product_id: option.id
			})
			.then(res => {
                
				this.setData({
					good: res.data
				})
			})
            
        if (option.share_user_id) {
            tt.setStorage({
                data: option.share_user_id,
                key: 'share_user_id',
            })
        }
		tt.setStorage({
			data: option.id,
			key: 'optionId',
		})
        this.setData({
			id: option.id
		})
	},
    onShow(){
        if(app.globalData.show==true){
            this.setData({
				show:true
			})
            this.setData({
				backStyle:"home"
			})
			this.getList()
        }
    },
	//获取提示框的列表
	getList(){
		api.reDuDetail()
				.then(res => {
					this.setData({
						list: res.data
					})
                    
				})
	},
	//提示框点击事件
	ljcsDetail(e){
		this.setData({
			show:false
		})
		api.ljcsChaxun({
			product_id: e.currentTarget.dataset.item.id
		})
		.then(res => {
			this.setData({
				good: res.data
			})
		})
	},
	del:function(){
		this.setData({
			show:false
		})
	},
	look(){
		tt.navigateTo({
			url: '../../pages/liebiao/liebiao?show=' + true + '&time=1',
		})
	},
	ljcsBtnClick: function() {
		api.shuXingChaXun({
				product_id: this.data.good.product_id
			})
			.then(res => {
				let data = ''
				if (res.data.length != 0) {
					data = JSON.stringify(res.data)
					let temp = JSON.stringify([
						this.data.good.img_url[1],
						this.data.good.background_url
					])
					let style = JSON.stringify([
						this.data.good.width,
						this.data.good.height
					])
					tt.navigateTo({
						url: '../xzsx/xzsx?product_id=' + this.data.good.product_id + '&data=' + data + '&img_url=' + temp +
							'&style=' +
							style,
					})
				} else {
					tt.navigateTo({
						url: '../tmxq/tmxq?product_id=' + this.data.good.product_id
					})
				}
			})
	}
})
